﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using CDB.LinqModel.Data;
using CDB.LinqModel;
using CDB.LinqData;
using System.Web.UI.WebControls;
using System.Collections.Generic;

public partial class Architects : System.Web.UI.Page
{
    #region Variable Declaration

    private IDataRepository _dataObject = new DataRepository();
    private Architect architect;
    private List<Architect> architects = new List<Architect>();
    private City city;
    private List<City> cities = new List<City>();

    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //BindCities();
        }
    }

    private void BindCities()
    {
        city = new City(_dataObject);
        //cities = city.GetCitiesByArchitects();

        //if (cities.Count > 0)
        //{
        //    ddlCity.DataSource = cities;
        //    ddlCity.DataTextField = "Name";
        //    ddlCity.DataValueField = "Id";
        //    ddlCity.DataBind();
        //    ddlCity.Items.Insert(0, "Select City");
        //}
    }

    protected void DdlCitySelectedIndexChanged(object sender, EventArgs e)
    {
        BindArchitectsGrid();
    }

    private void BindArchitectsGrid()
    {
        architect = new Architect(_dataObject);
        architects = architect.GetArchitectsByLocation(ddlCity.SelectedValue);
        if (architects.Count > 0)
        {
            dListArchitects.DataSource = architects;
            dListArchitects.DataBind();
        }
        else
        {
            dListArchitects.DataSource = null;
            dListArchitects.DataBind();
        }
    }

    protected void GrdArchitectsRowDataBound(object sender, GridViewRowEventArgs e)
    {
        //grdArchitects.Rows[0].TableSection = TableRowSection.TableHeader;
    }
    protected void dListArchitects_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HtmlGenericControl spDateCreated = (HtmlGenericControl)e.Item.FindControl("spDateCreated");
            Label spanDate = (Label)e.Item.FindControl("spanDate");

            spDateCreated.InnerHtml = "<small>" +
                                      ((CDB.LinqModel.CDBGeneral.Month) Convert.ToDateTime(spanDate.Text).Month).
                                          ToString() + "</small>";
            spDateCreated.InnerHtml += "<div>" +
                                       (Convert.ToDateTime(spanDate.Text).Day).
                                           ToString() + "</div>";

        }
    }
}